package nickname;

import java.net.Inet4Address;
import java.net.InetAddress;
import java.net.UnknownHostException;

public abstract class GGServerIpProvider {
	
	public static final int PORT = 8074;
	public static final int TIMEOUT = 50;
	
	private static String[] servers = {
		"91.197.13.10",
		"91.197.13.11",
		"91.197.13.12",
		"91.197.13.13",
		"91.197.13.14",
		"91.197.13.15",
		"91.197.13.16",
		"91.197.13.17",
		"91.197.13.18",
		"91.197.13.19",
		"91.197.13.2",
		"91.197.13.20",	
		"91.197.13.21",
		"91.197.13.24",
		"91.197.13.25",
		"91.197.13.26",
		"91.197.13.27",
		"91.197.13.28",
		"91.197.13.29",
		"91.197.13.3",
		"91.197.13.30",
		"91.197.13.3",
		"91.197.13.32",
		"91.197.13.33",
		"91.197.13.34",
		"91.197.13.35",
		"91.197.13.36",
		"91.197.13.37",
		"91.197.13.38",
		"91.197.13.39",
		"91.197.13.4",
		"91.197.13.40",	
		"91.197.13.41",
		"91.197.13.42",
		"91.197.13.43",
		"91.197.13.44",
		"91.197.13.45",
		"91.197.13.46",
		"91.197.13.49",
		"91.197.13.5",
		"91.197.13.51",	
		"91.197.13.52",
		"91.197.13.53",
		"91.197.13.54",
		"91.197.13.6",
		"91.197.13.66",	
		"91.197.13.67",
		"91.197.13.68",
		"91.197.13.69",
		"91.197.13.7",
		"91.197.13.70",	
		"91.197.13.71",
		"91.197.13.72",
		"91.197.13.73",
		"91.197.13.74",
		"91.197.13.75",
		"91.197.13.76",
		"91.197.13.77",
		"91.197.13.78",
		"91.197.13.79",
		"91.197.13.8",
		"91.197.13.80",	
		"91.197.13.81",
		"91.197.13.82",
		"91.197.13.83",
		"91.197.13.84",
		"91.197.13.9",
		"91.197.13.93"	
	};

		
	
	public static String getGGServerIp(int timeout) {
		for (int i = 0; i < servers.length; i++) {
			String ip = servers[i];
			InetAddress byName;
			try {
				byName = Inet4Address.getByName(ip);
			} catch (UnknownHostException e) {
				continue;
			}
			
			if(Utils.pingGgServer(byName, PORT, timeout)){
				return "0 0 " + ip + ":" + PORT + " " + ip;
						
			}
		}
		return servers[13];
	}
	
	public static String getGGServerIp() {
		return getGGServerIp(TIMEOUT);
	} 
}
